<link rel="stylesheet" href="${request.contextPath}/static/oms/default/plugins/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link href="${request.contextPath}/static/oms/iframe/plugins/bootstrap-icon-picker/css/icon-picker.css"  rel="stylesheet" type="text/css" />
<div class="row">
	<div class="col-md-12">
		<div class="box-body  no-padding">
			<form id="add-from" class="form-horizontal" action="${request.contextPath}/blog/industry/add" method="post" onsubmit="return false">
				<div class="form-group">
					<label for="blogIndustryName" class="col-sm-2 control-label">名称</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="name"  id="blogIndustryName"  value="" placeholder="输入名称...">
					</div>
					<label id="blogIndustryParentIdLabel" for="blogIndustryParentId" class="col-sm-2  control-label">上级资源</label>
					<div class="col-sm-4">
						<div class="input-group">
							<input type="hidden" class="form-control" id="blogIndustryParentId" name="parentId"  value="" >
							<input type="text" class="form-control"  id="blogIndustryParentName" value="" placeholder="选择上级资源...">
							<span class="input-group-addon"><i class="glyphicon glyphicon-remove" style="color: #FF0000;" id="blogIndustryParentIdClear"></i></span>
							<div id="blogIndustryContent" class="blogIndustryContent" style="position: absolute; left: 0; top: 25px; display: none;z-index: 999999;">
								<ul id="blogIndustryParentTree" class="ztree" style="margin-top: 10px;
																border: 1px solid #d6e0df;
																background: #fbfbfb;
																width: 220px;
																height: 360px;
																overflow-y: scroll;
																overflow-x: auto; -moz-user-select: none;">
								</ul>
							</div>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label for="blogIndustryName" class="col-sm-2 control-label">编码</label>
					<div class="col-sm-2">
						<input type="text" class="form-control" name="code"  id="blogIndustryCode"  value="" placeholder="输入编码...">
					</div>
					<label id="blogIndustrySortOrderLabel" for="blogIndustrySortOrder" class="col-sm-2  control-label">排序号</label>
					<div class="col-sm-2">
						<input class="form-control" name="sortOrder" id="blogIndustrySortOrder" type="number" value="" placeholder="输入排序号...">
					</div>
					<label id="blogIndustryStatusLabel" for="blogIndustryStatus" class="col-sm-1  control-label">状态</label>
					<div class="col-sm-2">
						<select class="form-control" id="blogIndustryStatus"  name="status"  value="" style="width: 100%;">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="blogIndustryDescriptionLabel" class="col-sm-2 control-label" >描述</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="description" id="blogIndustryDescription"  value="" placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label id="blogIndustryRemarkLabel" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="remark" id="blogIndustryRemark"  value="" placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" >
					<span class="error-icon"></span>
					<span id="error-msg" class="error-msg" ></span>
				</div>
				<div class="box-footer">
					<div class="pull-right">
						<button type="submit" class="btn btn-primary btn-sm" ><i class="fa fa-save"></i> 保存</button>
						<button type="button" class="btn btn-default btn-sm" id="close" data-dismiss="modal"><i class="fa fa-close"></i>关闭</button>
					</div>
				</div>
			</form>
		</div>

	</div>
</div>
<script type="text/javascript" src="${request.contextPath}/static/oms/default/plugins/zTree/jquery.ztree.all.js"></script>
<script type="text/javascript" src="${request.contextPath}/static/oms/iframe/plugins/bootstrap-icon-picker/js/iconPicker.js"></script>
<script type="text/javascript">
    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "parentId",
                rootPId: null
            }
        },
        async: {
            enable: true,
            url:"/blog/industry/tree",
            dataFilter:function (treeId, parentNode, responseData) {
                if (responseData) {
                    for(var i =0; i < responseData.length; i++) {
                        responseData[i].url = null;
                    }
                }
                return responseData;
            }
        },
        callback:{
            onAsyncSuccess:function (event, treeId) {
                var node = $.fn.zTree.getZTreeObj(treeId).getNodeByParam("id", $("#blogIndustryParentId").val());
                if(node){
                    $("#blogIndustryParentName").val(node.name);
                }
            },
            onClick :function (event, treeId, treeNode) {
                $("#blogIndustryParentId").val(treeNode.id);
                $("#blogIndustryParentName").val(treeNode.name);
                $('#blogIndustryContent').hide();
            }
        }
    };
	$(function() {

        $("#blogIndustryIcon").iconPicker();

		$("#blogIndustryStatus").select2({
			data: StatusStore,
			language: "zh-CN",
            theme: "bootstrap"
		});

		setting.async.url="/blog/industry/tree";
		$.fn.zTree.init($('#blogIndustryParentTree'), setting);

        $("#blogIndustryParentName").on('click',function () {
            $('#blogIndustryContent').css("display")==='none'?$('#blogIndustryContent').show():$('#blogIndustryContent').hide();
        });
        $("#blogIndustryContent").mouseleave(function () {
            $('#blogIndustryContent').hide();
        });

        $("#blogIndustryParentIdClear").on('click',function () {
            $("#blogIndustryParentId").val("");
            $("#blogIndustryParentName").val("");
        });

        function ajaxSubmit(form) {

            var $form = $(form);

            if ($form.length === 1 && $form.validate()) {
                $.post(form.action, $form.serialize(),
                    function(result) {
                        if (result.success) {
                            $("#lgModal").modal('hide');
                            alertMsg(result.message,"success");
                            window.location.reload();
                        } else {
                            $form.find(".error-msg").show();
                            $form.find(".error-msg").html(result.message);
                        }
                    }, 'json');
            }
        }

        var $addForm = $("#add-from");
        $addForm.validate({
            rules: {
                name: {
                    required: true
                },
                code: {
                    required: true
                },
                sortOrder: {
                    required: true
                }
            },
            messages: {
                name:{
                    required:"名称不能为空！"
                },
                code: {
                    required: "编码不能为空！"
                },
                sortOrder: {
                    required: "排序号不能为空！"
                }
            },
            submitHandler:ajaxSubmit,
            errorLabelContainer:".error-msg",
            wrapper:"li",
            showErrors:function(errorMap,errorList) {
                if(errorList.length>0){
                    $addForm.find(".error-msg").html(errorList[0].message);
                }else{
                    $addForm.find(".error-msg").html("");
                }
            },
            onkeyup: false
        });
    });
</script>
